﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace EC2011_hk1_BT6_1041326_1041337_1041373_1041448.UserControls
{
    public partial class MenuDSPhongBan : System.Web.UI.UserControl
    {
        private MenuItem _itemNavigation;
        private List<DTO.DepartmentDTO> _departments;

        public MenuDSPhongBan()
        {
            _departments = new List<DTO.DepartmentDTO>();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Init page
            if (!Page.IsPostBack)
            {

                LoadDepartmentMenuNavigation();

                LoadMenuNavigation();
            }
        }
        /// <summary>
        /// LoadMenuNavigation method to output department menu from database
        /// </summary>
        protected void LoadMenuNavigation()
        {
            // Refresh department menu
            this.mDepartmentList.Items.Clear();

            // Check not exists any department in database 
            if (_departments.Count < (int)MasterPages.MasterPage.ListStateE.minScale)
            {
                _itemNavigation = new MenuItem(Resources.Global.Messages_Department_Empty);
                this.mDepartmentList.Items.Add(_itemNavigation);
                _itemNavigation = null;
                return;
            }

            foreach (DTO.DepartmentDTO item in _departments)
            {
                _itemNavigation = new MenuItem(item.Name);
                _itemNavigation.Value = item.DepartmentID.ToString();
                this.mDepartmentList.Items.Add(_itemNavigation);
                _itemNavigation.NavigateUrl = "~/Presentation/NhanVienTheoPhongBan.aspx?PhongBanID=" + item.DepartmentID; ;
            }

        }
        protected void LoadDepartmentMenuNavigation()
        {
            // Get departments from database
            _departments = BUS.DepartmentBUS.GetAll();
        }
    }
}